#ifndef _UTILEX_COND_HPP_
#define _UTILEX_COND_HPP_

#include <crt_util.h>

#ifdef __cplusplus

class CCondHandle
{
public:
    CCondHandle()
    {
        this->m_h.relative = WAIT_TIME_RELATIVE;
        _cond_init(&this->m_h);
    }
    ~CCondHandle() { Close(); }

    HRESULT Close()
    {
        _cond_destroy(&this->m_h);
        return S_OK;
    }
    HRESULT Wait()
    {
        _cond_wait(&this->m_h);
        return S_OK;
    }
    HRESULT WaitTime(int sec)
    {
        _cond_timedwait(&this->m_h, sec);
        return S_OK;
    }

    HRESULT Signal()
    {
        _cond_signal(&this->m_h);
        return S_OK;
    }

    HRESULT Broadcast()
    {
        _cond_broadcast(&this->m_h);
        return S_OK;
    }

public:
    _cond_t m_h;
};

#endif

#endif
